<template>
	<div>
		<label>输入密码：</label>
		<u-textarea v-model="password"></u-textarea>
		<button @click="encryptPassword">AES加密</button>
		<button @click="decryptPassword">AES解密</button>
		<button @click="iceMD5SHA1SHA256('MD5')">MD5加密</button>
		<button @click="iceMD5SHA1SHA256('SHA1')">SHA1加密</button>
		<button @click="iceMD5SHA1SHA256('SHA256')">SHA256加密</button>
		<button @click="chartCrypto">chartCrypto加密</button>
		<button @click="clear">清空解密结果</button>
		<button @click="createKsCode">快手粉条工具激活码生成</button>
		<u-textarea v-model="encryptedPassword"></u-textarea>
		<u-textarea v-model="decryptedPassword"></u-textarea>
	</div>
</template>

<script>
	import CryptoJS from 'crypto-js';
	export default {
		data() {
			return {
				password: 'ffefa898c520ccc937a2a1a0dc7f68b51b25d8ddbebebcbcb3b2b1ab',
				encryptedPassword: '',
				decryptedPassword: '',
			};
		},
		created() {
			// this.iceMD5SHA1SHA256('MD5')
		},
		methods: {
			clear(){
				// this.encryptedPassword=''
				this.decryptedPassword=''
			},
			encryptPassword() {
				const cipherPassword = CryptoJS.AES.encrypt(this.password, 'secret key 123').toString();
				this.encryptedPassword = cipherPassword;
			},
			decryptPassword() {
				const bytes = CryptoJS.AES.decrypt(this.encryptedPassword, 'secret key 123');
				const originalText = bytes.toString(CryptoJS.enc.Utf8);
				this.decryptedPassword = originalText;
			},
			iceMD5SHA1SHA256(KEY){
				this.encryptedPassword = `iceSign:${CryptoJS[KEY](this.password).toString()}`;
			},
			chartCrypto(){
				// 盐值
				const salt = "random_salt";
				// 获取当前时间戳
				// const timestamp = Math.floor(Date.now() / 1000);
				const timestamp = 123;
				// 公钥
				const publicKey = "your_public_keyyour_public_key";
				// 要加密的数据
				const data = {
					name: 'John Doe',
					email: 'johndoe@example.com'
				};
				// 将数据转换为JSON字符串
				const jsonData = JSON.stringify(data);
				// 组合需要加密的字符串
				const encryptString = jsonData + salt + timestamp;
				// 使用公钥进行加密
				const first = CryptoJS.MD5(encryptString).toString()+'ice369';
				const second = CryptoJS.MD5(first).toString();
				// 输出加密后的数据
				console.log(second);
			},
			createKsCode(){
				this.encryptedPassword = CryptoJS.MD5(CryptoJS.MD5(CryptoJS.MD5(this.password).toString()+'ice').toString()+'721').toString()
			}
		},
	};
	
</script>